<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link href="../cwjy/css/app.css" rel="stylesheet">
    <style>
        html::-webkit-scrollbar {
            display: none
        }
    </style>
</head>
<script src="../cwjy/js/app.js"></script>
<script src="../cwjy/js/jquery.min.js"></script>
<body>
<div class="modal-content">
    <div class="modal-header" id="modelHead">
        <h5 class="card-title" style="font-weight: bold;font-size: 20px;text-shadow: 1px 1px 2px #000000;">
            用户详细</h5>
    </div>
    <div class="modal-body m-3">
        <div class="card-body" id="modelDiv"
             style="font-weight: bold;font-size: 15px;text-shadow: 2px 2px 2px #cccccc;">
            <div class="mb-3 row">
                <label class="col-form-label col-sm-2 text-sm-right">姓名</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" id="name" placeholder="姓名">
                </div>
            </div>
            <div class="mb-3 row">
                <label class="col-form-label col-sm-2 text-sm-right">用户名</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" id="username" placeholder="用户名">
                </div>
            </div>
            <div class="mb-3 row">
                <label class="col-form-label col-sm-2 text-sm-right">密码</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" id="password" placeholder="密码">
                </div>
            </div>
            <fieldset class="mb-3" id="is_pregnancy_or_estrus">
                <div class="row">
                    <label class="col-form-label col-sm-2 text-sm-right pt-sm-0">性别</label>
                    <div class="col-sm-10">
                        <label class="form-check">
                            <input name="radio-4" type="radio" id='1' class="form-check-input" checked>
                            <span class="form-check-label">男</span>
                        </label>
                        <label class="form-check">
                            <input name="radio-4" type="radio" id='2' class="form-check-input">
                            <span class="form-check-label">女</span>
                        </label>
                    </div>
                </div>
            </fieldset>

            <div class="mb-3 row">
                <label class="col-form-label col-sm-2 text-sm-right">家庭住址</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" id="home_address" placeholder="家庭住址">
                </div>
            </div>
            <div class="mb-3 row">
                <label class="col-form-label col-sm-2 text-sm-right">年龄</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" id="age" placeholder="年龄">
                </div>
            </div>
            <div class="mb-3 row">
                <label class="col-form-label col-sm-2 text-sm-right">联系电话</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" id="phone" placeholder="联系电话">
                </div>
            </div>
            <div class="mb-3 row">
                <label class="col-form-label col-sm-2 text-sm-right">创建时间</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" id="create_date" placeholder="创建时间">
                </div>
            </div>
            <div class="mb-3 row">
                <label class="col-form-label col-sm-2 text-sm-right">创建人</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" id="create_user" placeholder="创建人">
                </div>
            </div>
        </div>
    </div>
    <div  id="modelAction" style="text-align: center">
        <button type="button" class="btn btn-secondary" data-dismiss="modal" style="margin-right: 10%">关闭</button>
        <button type="button" class="btn btn-primary" onclick="addUserData()">提交</button>
    </div>
</div>
</body>
<script type="text/javascript" src="../cwjy/js/ajaxAll.js"></script>
<script type="text/javascript">
    function addUserData() {
        let name = $('#name').val();
        let username = $('#username').val();
        let password = $('#password').val();
        let home_address = $('#home_address').val();
        let phone = $('#phone').val();
        let age = $('#age').val();
        let sex_radio = $('input:radio[name="radio-4"]:checked');
        let sex = sex_radio[0].id;
        let url = "http://localhost:8888/cwjy/user/insert";
        let json = {
            name: name, username: username, password: password, home_address: home_address,
            phone: phone, age: age, sex: sex
        };
        if(name === "" || username === "" || password === "" || phone === "" || age === "" || sex === ""  ){
            alert('有选项未输入，请输入！');
            return;
        }
       if(!isPhoneNo(phone)){
            alert("输入手机号码有误，请重新输入！")
           return;
        }
        let success = "增加成功";
        let error = "增加失败";
        ajaxUnifiedCallUpdateAndAdd(url, json, success, error)
    }
</script>
</html>